Reject Content-Length longer than 1 billion TB #181
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
So there is this CVE on CPython https://www.cve.org/CVERecord?id=CVE-2020-10735, the problem is that parsing a base-10 integer with
int()is quadratic. A rogue agent can forge a badContent-Lengthheader with a huge integer to DOS h11.The way the bug was solved in CPython 3.11 was to verify the length of the
intinput, to make sure it stayed under a reasonable limit (4300 digits by default).So using h11 with Py3.11, we get a
ValueErrorwhen we try to parses a rogue Content-Length. But in Py3.8.2 (the lowest I have on my machine) it takes ages to parse it.Consider the folowing example:
So we craft a response with a Content-Length with 1MB digits.
The script takes 7 seconds to run:
Changing the
Content-Lengthfor another header (e.g.Content-Type) we don't have any problem.This PR solves 2 things:
h11.ProtocolErrorinstead of aValueError.